package com.example.exe;

import android.widget.Toast;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import app.auto.runner.ActivityBase;

/**
 * Created by hp on 2018/3/7.
 */

public class Test extends ActivityBase {
    private String toast(String cmd) {
        Toast.makeText(this, cmd, Toast.LENGTH_SHORT).show();
        return "ok";
    }

    public static Object invokePrivate(Class clz, String method, Class[] args, Object[] values, Object clzobj) {
        try {
            Method m = clz.getDeclaredMethod(method, args);
            m.setAccessible(true);
            Object value = m.invoke(clzobj, values);
            return value;
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        }
        return "";
    }

    public static Object invoke(Class parentclz,String name, Object childobj) {
        Field m = null;
        try {
            m = parentclz.getDeclaredField(name);
            m.setAccessible(true);
            Object value = m.get(childobj);
            return value;
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        return "";
    }
}
